/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
public:
    // 后序遍历
    /*
    int TreeDepth(TreeNode* root) {
        if(!root) return 0;
        int left = TreeDepth(root->left);
        int right = TreeDepth(root->right);
        return max(left,right) + 1;
    }
    */
    // 先序遍历
    int ans = 0;
    int TreeDepth(TreeNode* root) {
        recur(root, 1);
        return ans;
    }
    void recur(TreeNode* root, int depth) {
        if(!root) return ;
        ans = max(ans,depth);
        recur(root->left, depth+1);
        recur(root->right, depth+1);
    }
};